package com.example.wangzh.developkit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.wangzh.developkit.R;
import com.example.wangzh.developkit.widget.CountDownView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wangzh on 2017/10/20.
 */

public class CountDownAdapter extends BaseAdapter {
    Context context;
    List<Long> longs;

    public CountDownAdapter(Context context, List<Long> longs) {
        this.context = context;
        this.longs = longs;
    }

    @Override
    public int getCount() {
        return longs.size();
    }

    @Override
    public Object getItem(int position) {
        return longs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.list_item_countdown,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.countDownView.setRemainTime(longs.get(position));
        return convertView;
    }

    class ViewHolder{
        public ViewHolder(View view) {
            ButterKnife.bind(this,view);
        }
        @BindView(R.id.countDownView)
        CountDownView countDownView;
    }
}
